package com.alex.users;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.OutputStream;

@Controller
public class TestUserController {

    @RequestMapping(value="/", method = RequestMethod.POST)
    public ModelAndView handleRequestroot(HttpServletRequest request, HttpServletResponse response) throws Exception{
        System.out.println("/demo_index");


        return null;
    }
    @RequestMapping(value="/user",method = RequestMethod.POST)
    public ModelAndView excute(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("userController.....!!!!!");
        resp.setHeader("Content-type","text/html;charset=UTF-8");//向浏览器发送一个响应头，设置浏览器的解码方式为UTF-8

        String data = "中国 Post";

        OutputStream stream = resp.getOutputStream();

        stream.write(data.getBytes("UTF-8"));
        return null;
    }
    @RequestMapping(value="/user",method = RequestMethod.GET)
    public ModelAndView excute1(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        System.out.println("userController.....!!!!!");
        resp.setHeader("Content-type","text/html;charset=UTF-8");//向浏览器发送一个响应头，设置浏览器的解码方式为UTF-8

        String data = "中国 GET";

        OutputStream stream = resp.getOutputStream();

        stream.write(data.getBytes("UTF-8"));
        return null;
    }
    @RequestMapping(value="/demo1")
    public ModelAndView handleRequest0(HttpServletRequest request, HttpServletResponse response) throws Exception{
        System.out.println("/demo1");


        return null;
    }
    @RequestMapping(value="/demo2")
    public ModelAndView handleRequest1(HttpServletRequest request, HttpServletResponse response) throws Exception{
        System.out.println("demo1");
        return  null;
    }
    @RequestMapping(value="/demo3")
    public ModelAndView handleRequest2(HttpServletResponse response,HttpServletRequest request) throws Exception{
        System.out.println("demo3");
        request.getParameter("");
        return  null;
    }
    @RequestMapping(value="/demo4")
    public ModelAndView handleRequest3(HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception{
        System.out.println("demo3");
        request.getParameter("");
        return  null;
    }
    @RequestMapping(value="/demo5")
    public ModelAndView handleRequest3(String user) throws Exception{

        String userss = user;
        System.out.println(user);
        ModelAndView mv = new ModelAndView("/WEB-INF/views/demo.jsp");
        mv.addObject("msg","第一个基于注解的 controller 方法");

        return  mv;
    }
    @RequestMapping("/demo6")
    public ModelAndView handleRequest6(String user) throws Exception{

        String userss = user;
        System.out.println(user);
        ModelAndView mv = new ModelAndView("/WEB-INF/views/demo.jsp");
        mv.addObject("msg","第一个基于注解的 controller 方法");

        return  mv;
    }
}
